//
// Created by wangxiyue on 2019/9/25.
//

#include <stdio.h>

void print(int *a, int low, int high) {
    for (int i = low; i <= high; i++) {
        printf("%d\t", a[i]);
    }
    printf("\n");
}

void quick_sort(int *a, int low, int high) {

    if (low >= high) {
        return;
    }

    int i = low;
    int j = high;
    int std = a[low];
    while (i < j) {
        while (i<j&&a[j] >= std) {
            j--;
        }
        if (a[j] < std) {
            a[i++] = a[j];
        }
        while (i<j&&a[i] <= std) {
            i++;
        }
        if (a[i] > std) {
            a[j--] = a[i];
        }
    }
    a[i] = std;
    printf("std=%d,i=%d,low=%d,high=%d,a=", std, i, low, high);
    print(a, low, high);
    quick_sort(a, low, i - 1);
    quick_sort(a, i + 1, high);
}

int main() {
    int a[] = {5, 1, 3, 2, 4, 0};
    print(a, 0, 5);
    quick_sort(a, 0, 5);
    print(a, 0, 5);
    return 0;
}
